package proiect.fis.UI;

import javax.swing.DefaultComboBoxModel;
import proiect.fis.UI.comboBoxModel.OrasModel;
import proiect.fis.commons.beans.Oras;
import proiect.fis.commons.beans.TipPachet;

/**
 *
 * @author Boogie
 */
public class CityView extends javax.swing.JPanel {

    private Oras oras;

    /**
     * Creates new form CityView
     */
    public CityView() {
        initComponents();
        init();
    }

    private void init() {
        DefaultComboBoxModel<Oras> model = OrasModel.createModel();
        comboBoxConexiune.setModel(model);
    }

    public void setOras(Oras o) {
        this.oras = o;

        this.textFieldNumeOras.setText(o.getNume());
        switch (o.getTipRuta()) {
            case PERICULOS:
                checkBoxPretios.setSelected(true);
                break;
            case NORMAL:
                checkBoxNormal.setSelected(true);
                break;
            case PRETIOS:
                checkBoxPericulos.setSelected(true);
                break;
        }


        comboBoxConexiune.getModel().setSelectedItem(o.getConexiune());


    }
    public boolean isValidInput(){
        for(int i =0;i<comboBoxConexiune.getModel().getSize();i++){
            Oras o = (Oras) comboBoxConexiune.getModel().getElementAt(i);
            if(o.getNume().equalsIgnoreCase(this.textFieldNumeOras.getText())){
                return false;
            }
        }
        return true;
    }

    public Oras getOras() {
        if (oras == null) {
            oras = new Oras();
        }
        oras.setConexiune((Oras) comboBoxConexiune.getSelectedItem());
        oras.setNume(textFieldNumeOras.getText());
        if (checkBoxNormal.isSelected()) {
            oras.setTipRuta(TipPachet.NORMAL);
        } else if (checkBoxPericulos.isSelected()) {
            oras.setTipRuta(TipPachet.PERICULOS);
        } else if (checkBoxPretios.isSelected()){
            oras.setTipRuta(TipPachet.PRETIOS);
        }else{
            oras.setTipRuta(TipPachet.FRAGIL);
        }

        return oras;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        javax.swing.ButtonGroup buttonGroup1 = new javax.swing.ButtonGroup();
        javax.swing.JLabel jLabel1 = new javax.swing.JLabel();
        textFieldNumeOras = new javax.swing.JTextField();
        javax.swing.JLabel jLabel2 = new javax.swing.JLabel();
        comboBoxConexiune = new javax.swing.JComboBox();
        javax.swing.JLabel jLabel3 = new javax.swing.JLabel();
        checkBoxNormal = new javax.swing.JCheckBox();
        checkBoxPericulos = new javax.swing.JCheckBox();
        checkBoxPretios = new javax.swing.JCheckBox();
        checkBoxFragil = new javax.swing.JCheckBox();

        jLabel1.setText("Nume Oras:");
        jLabel1.setToolTipText("");

        jLabel2.setText("Conexiune:");

        jLabel3.setText("Tip Ruta:");

        buttonGroup1.add(checkBoxNormal);
        checkBoxNormal.setText("Normal");

        buttonGroup1.add(checkBoxPericulos);
        checkBoxPericulos.setText("Periculos");

        buttonGroup1.add(checkBoxPretios);
        checkBoxPretios.setText("Pretios");

        buttonGroup1.add(checkBoxFragil);
        checkBoxFragil.setText("Fragil");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(textFieldNumeOras)
                            .addComponent(comboBoxConexiune, 0, 319, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(checkBoxFragil)
                            .addComponent(checkBoxPretios)
                            .addComponent(checkBoxPericulos)
                            .addComponent(checkBoxNormal)
                            .addComponent(jLabel3))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(textFieldNumeOras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(comboBoxConexiune, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(checkBoxNormal)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(checkBoxPericulos)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(checkBoxPretios)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(checkBoxFragil)
                .addContainerGap(114, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox checkBoxFragil;
    private javax.swing.JCheckBox checkBoxNormal;
    private javax.swing.JCheckBox checkBoxPericulos;
    private javax.swing.JCheckBox checkBoxPretios;
    private javax.swing.JComboBox comboBoxConexiune;
    private javax.swing.JTextField textFieldNumeOras;
    // End of variables declaration//GEN-END:variables
}
